package com.xiaoshuidi.cloud.module.member.controller.app.questionnaireinfo;

import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.module.member.controller.admin.questionnaireinfo.vo.PreviewQuestionnaireInfo;
import com.xiaoshuidi.cloud.module.member.controller.app.questionnaireinfo.vo.ParticipateVO;
import com.xiaoshuidi.cloud.module.member.controller.app.questionnaireinfo.vo.UserQuestionnaireVO;
import com.xiaoshuidi.cloud.module.member.enums.ApiConstants;
import com.xiaoshuidi.cloud.module.member.service.questionnaireinfo.MemberQuestionnaireInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;

import static com.xiaoshuidi.cloud.framework.common.pojo.CommonResult.success;

@Tag(name = "租客APP - 问卷基本信息")
@RestController
@RequestMapping(ApiConstants.NAME + "/questionnaire-info")
@Validated
public class AppMemberQuestionnaireInfoController {
    @Resource
    private MemberQuestionnaireInfoService memberQuestionnaireInfoService;

    @GetMapping("/preview-questionnaire/{id}")
    @Operation(summary = "预览问卷")
    @PermitAll
    public CommonResult<PreviewQuestionnaireInfo> previewQuestionnaire(@PathVariable("id") Long id) {
        return success(memberQuestionnaireInfoService.previewQuestionnaire(id));
    }


    @GetMapping("/other/preview-questionnaire")
    @Operation(summary = "预览问卷")
    @PermitAll
    public CommonResult<PreviewQuestionnaireInfo> otherPreviewQuestionnaire(String key) {
        return success(memberQuestionnaireInfoService.otherPreviewQuestionnaire(key));
    }


    @PostMapping("/participate/or/not")
    @Operation(summary = "是否已参加问卷")
    @PermitAll
    public CommonResult<Boolean> participateOrNot(@Validated @RequestBody ParticipateVO participateVO) {
        return success(memberQuestionnaireInfoService.participateOrNot(participateVO));
    }

    @PostMapping("/answer")
    @PermitAll
    @Operation(summary = "租客填写问卷")
    public CommonResult<Boolean> answer(@Validated @RequestBody UserQuestionnaireVO vo) {
        return success(memberQuestionnaireInfoService.answer(vo));
    }

    @PostMapping("/other/participate/or/not")
    @Operation(summary = "是否已参加问卷")
    @PermitAll
    public CommonResult<Boolean> otherParticipateOrNot(String key) {
        return success(memberQuestionnaireInfoService.otherParticipateOrNot(key));
    }

}
